<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="app" uri="http://www.wanrenhui.com" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
	  <%@include file="/res/include/base-head.jsp"%>
	  <%@include file="/res/include/jquery-easyui.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/mall/product.js"></script>
  </head>
  <body>
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',border:false,split:false">
	    	<form id="query-form" class="search_form clearfix">
	            <dl>
					<dt>名称：</dt>
					<dd>
						<input name="name" id="name" type="text" class="txt" maxlength="16"/>
					</dd>
				</dl>
				<dl>
	                <dt>分类：</dt>
	                <dd id="category">
	                	<select id="category_1" onchange="getChildrenCategory(this.value,1)" class="txt" name="categoryIds">
	                		<option value="">--请选择--</option>
	                		<c:forEach var="categoryVo" items="${mallCategoryVoList}">
	                			<option value="${categoryVo.categoryId }">${categoryVo.name }</option>
	                		</c:forEach>
	                	</select>
	                </dd>
	            </dl>
	            <dl>
					<dt>状态：</dt>
					<dd>
	                	<select name="status" class="txt grid-10">
							<option value="">请选择</option>
							<option value="1">上架</option>
							<option value="2">下架</option>
							<option value="3">失效</option>
						</select>
					</dd>
				</dl>
	            <p class="search_form_btn">
	            	<input type="button" value="搜索" class="icon_serach" onclick="admin.product.query()" />
	            	<input type="button" value="添加" class="icon_serach" onclick="admin.product.toAdd('${shopId }')" />
	            </p>
	            </p>
	        </form>
	  	</div>
	    <div data-options="region:'center',border:false">
		    <table id="datagrid" data-options="url:'${pageContext.request.contextPath}/mall/product/list?shopId=${shopId }',toolbar:'#toolbar'">
				<thead>
					<tr>
						<th data-options="field:'name',width:200,align:'center'">名称</th>
						<th data-options="field:'status',width:80,align:'center',formatter:formatStatus">状态</th>
						<th data-options="field:'categoryName',width:100,align:'center'">分类</th>
						<th data-options="field:'brandName',width:100,align:'center'">品牌</th>
						<th data-options="field:'stock',width:80,align:'center'">库存</th>
						<th data-options="field:'saleCount',width:80,align:'center'">销量</th>
						<th data-options="field:'price',width:80,align:'center'">价格</th>
						<th data-options="field:'isRecommend',width:80,align:'center',formatter:formatIsRecommend">店铺主页推荐</th>
			            <th data-options="field:'id',align:'center',width:150,formatter:formatOperation">操作</th>
					</tr>
				</thead>
			</table>
	  	</div>
	</div>

	<script>
		function formatStatus(value,row,index) {
			var l_html = '上架';
			if (value==2) {
				l_html = '下架';
			} else if (value==3) {
				l_html = '失效';
			}
			return l_html;
		}
		function formatIsRecommend(value,row,index) {
			var l_html = '不推荐';
			if (value==1) {
				l_html = '推荐';
			}
			return l_html;
		}
		function formatOperation(value,row,index) {
			var l_html = '';
			l_html += '<a href="javascript:;" class="table_link" onclick="admin.product.toEdit('+row.id+')">编辑</a>';
			if (row.shopId != 1 && row.status == 1) {
				var recommendText = '首页推荐';
				var recommendValue = 1;
				if (row.discoverRecommend == recommendValue) {
					recommendText = '取消推荐';
					recommendValue = 2;
				}
				l_html += '|<a href="javascript:;" class="table_link" onclick="admin.product.setDiscoverRecommend('+row.id+',\''+recommendValue+'\')">'+recommendText+'</a>';
			}
			return l_html;
		}
		
		var qlevel = 1;
		function getChildrenCategory(parentId,level) {
			for (var i = (level+1); i <= qlevel; i++) {
				$('#category_'+i).remove();
			}
			if (parentId != "") {
				qlevel = level;
				var data = {parentId:parentId}
				$.post(contextPath+'/mall/category/findChildren',data,function(result) {
					if(result.code==1) {
						if (result.map.childrenList && result.map.childrenList.length > 0) {
							qlevel = level + 1;
							var childrenList = result.map.childrenList;
							var html = [];
							html.push('<select class="txt" id="category_'+qlevel+'" onchange="getChildrenCategory(this.value,'+qlevel+')" name="categoryIds">');
							html.push('<option value="">请选择</option>');
							for (var i = 0; i < childrenList.length; i++) {
								html.push('<option value="'+childrenList[i].categoryId+'">'+childrenList[i].name+'</option>');
							}
							html.push('</select>');
							$('#category').append(html.join(""));
							$('#brand').html('<option value="">请选择</option>');
						}
					}
				});
				
			}
		}
	</script>
  </body>
</html>
